package whf.framework.ext.entity;

import java.util.List;

import whf.framework.entity.AbstractEntity;
import whf.framework.entity.Permissionable;
import whf.framework.entity.TreeNode;
import whf.framework.security.entity.Permission;
import whf.framework.util.Utils;

/**
 * @author wanghaifeng
 * @create Aug 6, 2006 11:34:28 PM
 * 
 */
public class MenuItem extends AbstractEntity implements TreeNode<MenuItem>, Permissionable{
	private final static long serialVersionUID = 0;
	
	private String href;
	
	private MenuItem parent;
	
	/**
	 * 辅助属性，用于保存当前菜单项所有的子菜单项
	 */
	private List<MenuItem> children = Utils.newArrayList();
	
	/**
	 * 排序
	 * @property int:sortOrder
	 */
	private int sortOrder;

	/**
	 * 绑定菜单到权限，用以确定是否显示
	 * @property Permission:permission
	 */
	private Permission permission;
	
	private boolean leaf;
	
	private String icon;
	/**
	 * 是否发布
	 */
	private boolean deployed;
	
	public String getHref() {
		if(this.href == null) return "";
		return href;
	}

	public void setHref(String redirectURL) {
		this.href = redirectURL;
	}

	public MenuItem getParent() {
		return parent;
	}

	public void setParent(MenuItem parent) {
		this.parent = parent;
	}

	public int getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(int sortOrder) {
		this.sortOrder = sortOrder;
	}

	/**
	 * @return Returns the permission.
	 */
	public final Permission getPermission() {
		return permission;
	}

	/**
	 * @param permission The permission to set.
	 */
	public final void setPermission(Permission permission) {
		this.permission = permission;
	}

	/**
	 * @return Returns the leaf.
	 */
	public boolean isLeaf() {
		return this.children.isEmpty();
	}

	/**
	 * @param leaf The leaf to set.
	 */
	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	@Override
	public int compareTo(Object obj) {
		if(!(obj instanceof MenuItem)) return 0;
		MenuItem item = (MenuItem)obj;
		return this.sortOrder - item.sortOrder;
	}

	public boolean isDeployed() {
		return deployed;
	}

	public void setDeployed(boolean deployed) {
		this.deployed = deployed;
	}

	/**
	 * @return the children
	 */
	public List<MenuItem> getChildren() {
		return children;
	}

	/**
	 * @param children the children to set
	 */
	public void setChildren(List<MenuItem> children) {
		this.children = children;
	}

	/**
	 * @return the icon
	 */
	public String getIcon() {
		return icon;
	}

	/**
	 * @param icon the icon to set
	 */
	public void setIcon(String icon) {
		this.icon = icon;
	}
}
